package com.web.controller;

import com.aliyun.oss.model.MultipartUpload;
import com.web.entity.ResponseResult;
import com.web.util.OssUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件上传的控制器
 */
@CrossOrigin
@RestController
public class UploadController {

    /**
     * 上传文件
     * MultipartFile 参数可以接受文件
     */
    @RequestMapping("/upload")
    public ResponseResult upload(MultipartFile file) throws IOException {
        //上传到OSS
        OssUtils.upload(file.getInputStream(),file.getName());
        //获得URL
        String url = OssUtils.getURL(file.getName());
        return new ResponseResult(200,"OK",url);
    }
}
